module.exports = (app) => {
  const { INTEGER, STRING, DATE, TEXT, FLOAT } = app.Sequelize;
  const moment = require("moment");
  // 配置（重要：一定要配置详细，一定要！！！）
  const Member = app.model.define("member", {
    id: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true,
      comment: "主键ID"
    },
    memname: {
      type: STRING(30),
      allowNull: false,
      defaultValue: "",
      unique: true,
      comment: "会员名称"
    },
    memlevel: {
      type: STRING(30),
      allowNull: false,
      defaultValue: "",
      comment: "会员等级"
    },
    discount: {
      type: FLOAT(5, 2),
      allowNull: false,
      defaultValue: 0,
      comment: "会员折扣"
    },
    lowpoint: {
      type: INTEGER,
      allowNull: false,
      defaultValue: 200,
      comment: "最低积分"
    },
    highpoint: {
      type: INTEGER,
      allowNull: false,
      defaultValue: 99999,
      comment: "最高积分"
    },
    desc: {
      type: TEXT,
      allowNull: false,
      defaultValue: "",
      comment: "会员相关"
    },
    creator: {
      type: STRING(30),
      allowNull: false,
      defaultValue: "",
      comment: "创建人"
    },
    created_time: {
      type: DATE,
      get() {
        const v = this.getDataValue("created_time");
        return v ? moment(v).format("YYYY-MM-DD HH:mm:ss") : v;
      }
    },
    updated_time: {
      type: DATE,
      get() {
        const v = this.getDataValue("created_time");
        return v ? moment(v).format("YYYY-MM-DD HH:mm:ss") : v;
      }
    }
  });

  // 关联
  Member.associate = function () {
    app.model.Member.hasMany(app.model.User, {
      foreignKey: "memberId"
    });
  };

  return Member;
};
